<!--待办中心&#45;&#45;待执行任务&#45;&#45;申请完成（单条项目申请）-->
<template>
  <a-drawer
    title="申请完成"
    :width="720"
    :visible="drawerVisible"
    :maskClosable="drawMaskClosable"
    :body-style="{ paddingBottom: '80px' }"
    @close="closeApplyComplete"
  >
    <a-row>
      <span style="color: red">*&nbsp;&nbsp;</span><span>完成百分比：</span>
      <a-input-number v-model="perc" :min="0" :max="100" style="width: 100%;margin: 8px 0px 8px 0px;" @change=""/>
    </a-row>
    <a-row>
      <span style="color: red">*&nbsp;&nbsp;</span><span>任务实际完成工期（天）：</span>
      <a-input-number v-model="days" :min="0" :max="100" style="width: 100%;margin: 8px 0px 8px 0px;" @change=""/>
    </a-row>
    <a-row>
      <span style="color: red">*&nbsp;&nbsp;</span><span>完成情况说明：</span>
      <a-textarea style="width: 100%;margin: 8px 0px 8px 0px;"
                  v-model="textareaValue"
                  :auto-size="{ minRows: 3, maxRows: 10 }"
      />
    </a-row>
    <div
      :style="{
          position: 'absolute',
          right: 0,
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e9e9e9',
          padding: '10px 16px',
          background: '#fff',
          textAlign: 'right',
          zIndex: 1,
        }"
    >
      <a-button :style="{ marginRight: '8px' }" @click="closeApplyComplete">
        取消
      </a-button>
      <a-button type="primary" @click="commitApplyComplete">
        确认
      </a-button>
    </div>
  </a-drawer>
</template>
<script>
import {getLastResourceHour, sumResource} from "@api/todoPage";
export default {
  name: "applyCompleteOnce",
  data() {
    return {
      drawerVisible: this.drawerVisible_p,
      textareaValue: '',
      perc: null,//完成百分比
      minPerc: 0,//完成百分比最小值
      days: 0,//实际工期
    }
  },
  props: {
    drawerVisible_p: {
      type: Boolean,
      default: false
    },
    assignmentOid: {
      type: String,
      default: 'OR:com.pisx.pmgt.assignment.PIResourceAssignment:1684958'
    },
    drawMaskClosable: {
      type: Boolean,
      default: false
    },//点击蒙层是否允许关闭
  },
  computed: {},
  watch: {
    drawerVisible_p(val) {
      this.perc = null
      this.days = null
      this.drawerVisible = val
    },
  },
  mounted() {
    console.log('当前的assignmentOid：', this.assignmentOid)
    this.getLastResourceHourB()
  },
  methods: {
    //关闭抽屉
    closeApplyComplete() {
      this.$emit('closeDraw')
    },
    //获取上一次汇报工时的记录
    getLastResourceHourB() {
      let parm = {
        "resources": [
          {
            "assignmentOid": this.assignmentOid
          }
        ]
      }
      getLastResourceHour(parm).then(res => {
        if (res && res.status === 200) {
          if (res.data && res.data.success == true) {
            if (res.data.data && res.data.data.length > 0) {
              this.perc = res.data.data[0].completePercent
              this.minPerc = res.data.data[0].completePercent
              this.days = res.data.data[0].completeTime
              this.textareaValue = ''
            } else {
              this.perc = 100
              this.minPerc = null
              this.days = null
              this.textareaValue = ''
            }
          }else{
            this.$message.error(res.data.message)
          }
        } else {
          this.$message.error('接口失败')
        }
      })
    },
    //完成审核，关闭抽屉
    commitApplyComplete() {
      // console.log('当前this.assignmentOid：', this.assignmentOid)
      if (this.perc == '' || this.days == '' || this.textareaValue == '') {
        this.$message.success('请输入必需项！')
      } else {
        let parm = {
          resources: [
            {
              assignmentOid: this.assignmentOid,
              completePercent: parseInt(this.perc),
              completeTime: parseInt(this.days),
              comment: this.textareaValue
            }
          ]
        }
        sumResource(parm).then(res => {
          console.log(res)
          if (res && res.status === 200) {
            if (res.data.success == true) {
              this.$message.success('申请成功！')
              this.perc = null
              this.minPerc = null
              this.days = null
              this.textareaValue = ''
              this.$store.commit('commitApplyAdd')//刷新抽屉中的数据
              this.$emit("closeDraw");
            } else {
              this.$message.error(res.data.message)
            }
          } else {
            this.$message.error('接口连接失败！')
          }
        })
      }
    },
  },
}
</script>
<style scoped lang="less">
.applyDraw_temp {
  /deep/ .ant-row {
    margin-bottom: 10px;
  }
  /deep/ .ant-drawer-content-wrapper {
    width: 520px !important;
  }
}
</style>